package com.hntxk.cqzd.diagnosis.bizcheck;

import com.hntxk.core.framework.bizchk.BaseBizCheck;
import com.hntxk.core.util.NumberUtil;
import com.hntxk.core.util.StringUtil;
import com.hntxk.cqzd.diagnosis.model.DiagnosisInfo;
import com.hntxk.cqzd.diagnosis.service.DiagnosisInfoService;


/**
 * 数据字典check
 * 
 * @author huang.biquan
 * @date 2019年11月2日
 */
public class DiagnosisInfoBizCheck extends BaseBizCheck<DiagnosisInfo> {

	private DiagnosisInfoService service;

	/**
	 * contruct;
	 */
	public DiagnosisInfoBizCheck(DiagnosisInfoService service) {
		super();
		this.service =service;
	}
	
	@Override
	public void addable(DiagnosisInfo t){
		
		// 判断是否要进行check;
		if (!isNeedBizCheck()) {
			return;
		}
		inputRequired(t);
	}


	@Override
	public void deletable(DiagnosisInfo t){
		// 判断是否要进行check;
		if (!isNeedBizCheck()) {
			return;
		}
	}

	@Override
	public void updatable(DiagnosisInfo model) {
		// 判断是否要进行check;
		if (!isNeedBizCheck()) {
			return;
		}
		inputRequired(model);
		
	}

	/**
	 * 必填项验证
	 * @param t 诊断结果
	 */
	private void inputRequired(DiagnosisInfo t){

		if (NumberUtil.isNull(t.getCreateUserId())){
			addError(t.getFetusSign()+"登记人ID不能为空");
			return;
		}
		if (StringUtil.isNull(t.getCreateUserName())){
			addError(t.getFetusSign()+"登记人名称不能为空");
			return;
		}

		if (1L == t.getInspectionItemId()){
			//羊穿
			if (null == t.getInspectionTime() && NumberUtil.isNotNull(t.getAfTypeId())){
				addError(t.getFetusSign()+"的羊穿检测时间不能为空");
			}else if (null != t.getInspectionTime() && NumberUtil.isNull(t.getAfTypeId())){
				addError(t.getFetusSign()+"的羊水性状不能为空");
			}

		}else if (2L == t.getInspectionItemId()){
			//脐穿
			if (null == t.getInspectionTime() && StringUtil.isNotNull(t.getPuncturePosition())){
				addError(t.getFetusSign()+"的脐穿检测时间不能为空");
			}else if (null != t.getInspectionTime() && StringUtil.isNull(t.getPuncturePosition())){
				addError(t.getFetusSign()+"的穿刺部位不能为空");
			}
		}else if (3L == t.getInspectionItemId()){
			//绒穿
			if (null != t.getInspectionTime()){
				if ( StringUtil.isNull(t.getMazaPosition())){
					addError("绒穿胎盘部位不能为空");
				}
				if ( StringUtil.isNull(t.getSampleQuantity())){
					addError("绒穿取样量不能为空");
				}
			}else if (StringUtil.isNotNull(t.getMazaPosition()) || StringUtil.isNotNull(t.getSampleQuantity())){
				addError("绒穿检测时间不能为空");
			}
		}else if (4L == t.getInspectionItemId()){
			//留存标本
			if (null != t.getInspectionTime()){
				if ( StringUtil.isNull(t.getSpecKeepId())){
					addError("标本项目不能为空");
				}
			}else if (StringUtil.isNotNull(t.getSpecKeepId())){
				addError("标本留存时间不能为空");
			}
		}
	}
}
